package com.ruoyi.project.pay;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.IpUtils;
import com.ruoyi.common.utils.Md5Utils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.channel.businessCapital.domain.BusinessCapital;
import com.ruoyi.project.channel.businessCapital.service.IBusinessCapitalService;
import com.ruoyi.project.channel.businessRate.domain.BusinessRate;
import com.ruoyi.project.channel.businessRate.service.IBusinessRateService;
import com.ruoyi.project.channel.channelAccount.service.IChannelAccountService;
import com.ruoyi.project.channel.channelCode.service.IChannelCodeService;
import com.ruoyi.project.channel.channelOrder.domain.ChannelOrder;
import com.ruoyi.project.channel.channelOrder.service.IChannelOrderService;
import com.ruoyi.project.channel.clientInfo.domain.ClientInfo;
import com.ruoyi.project.channel.payerBusinessInfo.domain.PayerBusinessInfo;
import com.ruoyi.project.channel.payerBusinessInfo.service.IPayerBusinessInfoService;
import com.ruoyi.project.channel.payerInfo.domain.PayerInfo;
import com.ruoyi.project.channel.payerInfo.service.IPayerInfoService;
import com.ruoyi.project.pay.domain.*;
import com.ruoyi.project.pay.facai.SignUtil;
import com.ruoyi.project.pay.vnet.SHA256WithRSAUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * swagger 测试方法
 *
 * @author ruoyi
 */
@Api("支付管理")
@Controller
@RequestMapping("/callback/*")
public class ThirdController extends BaseController {
    @Autowired
    private PayServiceImpl payService;
    @Autowired
    private IChannelOrderService channelOrderService;
    @Autowired
    private IChannelAccountService channelAccountService;
    //    private String privateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDL+EzOYUxX7iOvof3KuGPHGA8EfYzFv2q7VEQgEsIGbQk1OHwFn+14tdq3X42iPjcTHCiYdImemG8+xGr0Qk4EZq2UB3wt3A6K1c0eCNQUSvDPCGH81nQ4lASmNYCMfaYAkCOVQCe5EgpM1PaptMm6q4aOB+nQK6K6uboP+muvTp6TjeLieVOX3aUTOE6hbQKeEAtD4jqHsCORBqAMyADq1/Kp1pIzeFe0OFssjGO61Kj2gykHB5cc+tWgax60ill9iXTLWzEifGiQQUB1Ru0zBTrSGY80hc0fhUa61jiqnZnlneZDcScFAdFs4GvOH977lcL2IVx5xse9Ml5kQBqlAgMBAAECggEAPj7oMZM/2RWzjkXBTbw3tuqAqr4l17MyvzhYEfGnhI6B4Nv7/TtxHQViWdOvRXP3Gr3dJalq1htu15jZivExHea30hT2sIgXaAcXMbNABXFZS9UjEiXgEeQaBx8Mu9Mcdc+HDGUnujLnMctL+z5Q0cbGqVGA6SZn4tQLFBU4B6dLAlVJ5OAHUT3wB6x168xoKAOkUprYE3YIbE/t6Zl4lw/REihde1xPA39Df+v54FU0DKwMLwHFMrqTR9jnwA+q8FBIRsCEG9zgQ0mq+DEdjv70gjFGaTZYrv9ytSwoA0s9QtZBVPioO30IWTXJ+S+I96T2VNq9Wkx0JginjgAUAQKBgQDnTotmLJefiXRNlRllhrJwukOWww3zkE8MpViOVrzmX3ZDQ24UAHPTyp70ph24oQNe2O05M/QqOeMDTfwQgQ6tlRNh6mExAFmdTSkhLEgVK+v51xet3FxzORhGy1qu1eo2dKS+bAkeorZFNowtiPmDSnk4XXbiXc4Tp6YuwQOFuQKBgQDhvqg3+O3V1QAO6/A/ODCwWTPtDOxOkMx1GT5Sgr+1kjy3kRcxJZSPyxsndQfwKmsJyMwYcC8E/vLhcjoEdfK5bNK8+kJcVvYyeqw3BKR0FXqxmxZACFS+l+Ifns5QSgJvI7f50pFwKhzN34SJCQWQB1vZunG4GWNsk77NdAjyTQKBgQCZJQDYmkedQkW1pDUXajI0vq5HYEeZbn9YERVr0HPrV2MWr8tvBMmrfSj3NBDTkA+KObf+uq47Uu5B3t04FCqitOQLXUISTngG1PKZWxcypUzsswOjghXX2AKBxNv6i/kxKtN0nFUBapuhgbcX4uvIiINv1ToEMDVkAAjgRbzOSQKBgQDJq740Ytp20Zb/vaAfml9E7CwLdiQV/B3r7uVSaSRDXaWIiMIjUeNqopRbp52z3PFLCGvs2SvoVqs85QMXwRdat/F8ikaGn9nKNvVrIWaZnibCTD6QbeDndGC6xvChobyS9WICeS8c+UJKWYjZs4mYpjpURNAbG/NKqKMogKUNcQKBgQCMmlaD/0wywC5rKNbSAVA0rbYS4pWvukso9LixfNnWS5XudCM4fFbSmQeuremQfJ5FxxyRlTVMHl9G8KnC4QoxTkE2urptpQLz0z/rjpPnVGHnNpROcP4gv602+7HXwW1ww45GXX4zGwXdOxfSl5kXiWr+0cnX8ygZeIs0zDVGxA==";
//    private String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmOji8TA47cwgyr3sFjY7ZRrjJufyZSCluD5TFP1n2cADFl2mgPoYWjklDBWZ36Adu0QjHxVBGCoZt9Z2Pb/bwO2Cigi3Z+3IELJtpcPUSaiyGFGKwDjf5WmDIPeewr5vjrjkj/v8I3WF1Ny6jb/vO4PNmjKqGzplMANp+qM48m6AgJmEH5Nhv3go6WuertzDjH6bp4ko/i5W9HwjpK2MjQjq/LP0KaFs+lFSCo9eqOK7tnhMwiXwW/OG4HTUl93HdtlrxhMmsf6x5DOlxyRaUi+ayyIm/d2LNxowJEZHK4VRs+Y2YcG40bleSNV83tTenI82PvcNcBwatD1jal6DzQIDAQAB";
    @Autowired
    private PayConfig payConfig;
    @Autowired
    private IChannelCodeService channelCodeService;
    @Autowired
    private IPayerInfoService payerInfoService;
    @Autowired
    private IPayerBusinessInfoService payerBusinessInfoService;
    @Autowired
    private IBusinessRateService businessRateService;
    @Autowired
    private PayVnetServiceImpl payVnetService;
    @Autowired
    private IBusinessCapitalService businessCapitalService;
    private static final Logger log = LoggerFactory.getLogger(PayServiceImpl.class);

    /**
     * 知宇类型的接口
     *
     * @param pddCallMsg
     * @return
     */
    private String updateZYOrder(PddCallMsg pddCallMsg, String payerName) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(pddCallMsg.toString());
        if (!pddCallMsg.getReturncode().equals("00")) {
            log.info("updateZYOrder 00 失败");
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(pddCallMsg.getMemberid());
        searchPayInfo.getParams().put("payerName", payerName);
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("updateZYOrder 找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("updateZYOrder 找到多个商户");
            return "找到多个商户";
        }

        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        // 开始签名
        String signTemp = "amount=" + pddCallMsg.getAmount() + "&datetime=" + pddCallMsg.getDatetime() + "&memberid=" + pddCallMsg.getMemberid()
                + "&orderid=" + pddCallMsg.getOrderid() + "&returncode=" +
                pddCallMsg.getReturncode() + "&transaction_id=" + pddCallMsg.getTransaction_id() + "&key=" + payerInfos.get(0).getApiKey() + "";
        log.info(signTemp);
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, pddCallMsg.getSign());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatePddOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(pddCallMsg.getOrderid());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            log.info("updateZYOrder 找到多个商户");
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            log.info("updateZYOrder 找到两条相同的数据");
            return "找到两条相同的数据";
        }
        channelOrders.get(0).setPayAmount(pddCallMsg.getAmount());
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "OK";
        } else {
            return "ERROR";
        }
    }

    /**
     * 下游支付商调用的接口,告诉支付中心 订单已经完成了
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("pdd")
    @ResponseBody
    public String updatePddOrder(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        return updateZYOrder(pddCallMsg, "拼多多");
    }

    /**
     * 七星2 淘宝代付
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("qx2")
    @ResponseBody
    public String updateQx2Order(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        return updateZYOrder(pddCallMsg, "七星");
    }


    /**
     * 开心支付
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("kx")
    @ResponseBody
    public String updatKXOrder(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        return updateZYOrder(pddCallMsg, "开心支付");
    }

    @ApiOperation("森火中间页面")
    @GetMapping("shView/{orderId}")
    public String shView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/sh";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "森火");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("version=1.0");
        stringBuilder.append("&customerid=").append(businessRate.getPayerBusinessId());
        stringBuilder.append("&total_fee=").append(channelOrder.getAmount());
        stringBuilder.append("&sdorderno=").append(channelOrder.getPtOrderno());
        stringBuilder.append("&notifyurl=").append(callbackUrl);
        stringBuilder.append("&returnurl=").append(callbackUrl);
        stringBuilder.append("&").append(payerInfos.get(0).getApiKey());
        String sign = "";
        try {
            sign = Md5Utils.androidMD5(stringBuilder.toString());
            System.out.println("sign:" + sign);
        } catch (Exception e) {
        }
        stringBuilder.append("&").append(sign);
        SHCallMsg shCallMsg = new SHCallMsg();
        shCallMsg.setCustomerid(businessRate.getPayerBusinessId());
        shCallMsg.setPaytype(businessRate.getPayerPayType());
        shCallMsg.setTotal_fee(channelOrder.getAmount());
        shCallMsg.setSdorderno(channelOrder.getPtOrderno());
        shCallMsg.setNotifyurl(callbackUrl);
        shCallMsg.setReturnurl(callbackUrl);
        shCallMsg.setSign(sign);
        mmap.put("shCallMsg", shCallMsg);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "SH2";
    }

    /**
     * 森火回调
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @GetMapping("sh")
    @ResponseBody
    public String getSHOrder(SHCallMsg pddCallMsg) {
        if (!pddCallMsg.getStatus().equals("1")) {
            return "支付失败";
        }
        return "支付成功";
    }

    /**
     * 森火回调
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("sh")
    @ResponseBody
    public String updatSHOrder(SHCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(pddCallMsg.toString());
        if (!pddCallMsg.getStatus().equals("1")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(pddCallMsg.getCustomerid());
        searchPayInfo.getParams().put("payerName", "森火");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始签名
        String signTemp = "customerid=" + pddCallMsg.getCustomerid() + "&status=" + pddCallMsg.getStatus() + "&sdpayno="
                + pddCallMsg.getSdpayno() + "&sdorderno=" + pddCallMsg.getSdorderno()
                + "&total_fee=" + pddCallMsg.getTotal_fee() + "&paytype=" + pddCallMsg.getPaytype() + "&" + payerInfos.get(0).getApiKey() + "";
        log.info(signTemp);
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, pddCallMsg.getSign());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatePddOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(pddCallMsg.getSdorderno());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到两条相同的数据";
        }
        channelOrders.get(0).setPayAmount(pddCallMsg.getTotal_fee());
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 森火回调
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("vnet")
    @ResponseBody
    public String updatVnetOrder(VnetCallMsg vnetCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(vnetCallMsg.toString());
        if (!vnetCallMsg.getStatus().equals("1")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(vnetCallMsg.getMno());
        searchPayInfo.getParams().put("payerName", "vnet");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始签名
        boolean b = payVnetService.checkSign(vnetCallMsg.getSign(), payerInfos.get(0).getPublicKey(), payerInfos.get(0).getApiKey());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatePddOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(vnetCallMsg.getOrderno());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到两条相同的数据";
        }
        channelOrders.get(0).setPayAmount(vnetCallMsg.getAmount().divide(BigDecimal.valueOf(100L))); // 取回来的是分 要除以100
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation("开心中间页面")
    @GetMapping("kxView/{orderId}")
    public String kxView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/kx";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "开心支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }

        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        String stringSignTemp = "pay_amount=" + channelOrder.getAmount() + "&pay_applydate=" + time + "&pay_bankcode=" + businessRate.getPayerPayType()
                + "&pay_callbackurl=" + callbackUrl + "&pay_memberid=" + businessRate.getPayerBusinessId() + "&pay_notifyurl="
                + callbackUrl + "&pay_orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            log.info("kxView:" + stringSignTemp);
            sign = Md5Utils.androidMD5(stringSignTemp).toUpperCase();
            log.info("kxView加密结果:" + sign);
        } catch (Exception e) {
        }
        YhbCallMsg kxCallMsg = new YhbCallMsg();
        kxCallMsg.setPay_amount(channelOrder.getAmount());
        kxCallMsg.setPay_applydate(time);
        kxCallMsg.setPay_bankcode(businessRate.getPayerPayType());
        kxCallMsg.setPay_callbackurl(callbackUrl);
        kxCallMsg.setPay_memberid(businessRate.getPayerBusinessId());
        kxCallMsg.setPay_notifyurl(callbackUrl);
        kxCallMsg.setPay_orderid(channelOrder.getPtOrderno());
        kxCallMsg.setPay_md5sign(sign);
        kxCallMsg.setPay_productdesc("");
        kxCallMsg.setPay_productname("收款");
        kxCallMsg.setPay_productnum("");
        kxCallMsg.setPay_producturl("");
        mmap.put("kxCallMsg", kxCallMsg);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "ZY";
    }

    /**
     * 聚合回调
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("jh")
    @ResponseBody
    public String updatJHOrder(JHCallMsg jhCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(jhCallMsg.toString());
        if (!jhCallMsg.getStatus().equals("1")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(jhCallMsg.getAppid());
        searchPayInfo.getParams().put("payerName", "聚合支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始签名
        String signTemp = "appid=" + jhCallMsg.getAppid() + "&charge=" + jhCallMsg.getCharge() + "&chargemoney="
                + jhCallMsg.getChargemoney() + "&code=" + jhCallMsg.getCode()
                + "&create_time=" + jhCallMsg.getCreate_time() + "&discount=" + jhCallMsg.getDiscount()
                + "&money=" + jhCallMsg.getMoney() + "&orderid=" + jhCallMsg.getOrderid()
                + "&realmoney=" + jhCallMsg.getRealmoney() + "&status=" + jhCallMsg.getStatus() + "&key=" + payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, jhCallMsg.getSign());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatePddOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(jhCallMsg.getOrderid());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到两条相同的数据";
        }
        channelOrders.get(0).setPayAmount(jhCallMsg.getRealmoney());
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 聚合回调
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("ds/{no}")
    @ResponseBody
    public String updatDSOrder(DSCallMsg dsCallMsg, @PathVariable("no") String no, String price) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(dsCallMsg.toString());
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(no);
        searchPayInfo.getParams().put("payerName", "大圣");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始签名
        String signTemp = dsCallMsg.getOut_order_id() + price + dsCallMsg.getType() + dsCallMsg.getPaytime() + dsCallMsg.getExtend();
        String sign = Md5Utils.androidMD5(signTemp);
        boolean b = Md5Utils.vertifyAndroidMD5(sign + payerInfos.get(0).getApiKey(), dsCallMsg.getSign());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatePddOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(dsCallMsg.getOut_order_id());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到两条相同的数据";
        }
        channelOrders.get(0).setPayAmount(dsCallMsg.getPrice());
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation("擎天柱中间页面")
    @GetMapping("qtzView/{orderId}")
    public String qtzView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/qtz";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "擎天柱支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }
        String amount = (channelOrder.getAmount().multiply(BigDecimal.valueOf(100L)) + "").replace(".00", "").replace(".0", "");
        String stringSignTemp = payerInfos.get(0).getApiKey() + payerInfos.get(0).getBusinessNo() + channelOrder.getPtOrderno() + amount;
        String sign = "";
        try {
            log.info("加密字符串:" + stringSignTemp);
            sign = Md5Utils.getSHA256(stringSignTemp);
            log.info("加密后字符串:" + sign);
            stringSignTemp = "mchId=" + payerInfos.get(0).getBusinessNo() + "&order=" + channelOrder.getPtOrderno() + "&amount=" + amount +
                    "&notifyUrl=" + callbackUrl + "&successUrl=" + callbackUrl + "&errorUrl=" + callbackUrl + "&sign=" + sign;
            log.info("请求字符串:" + stringSignTemp);
            String payUrl = URLEncoder.encode(payerInfo.getServiceUrl() + "?" + stringSignTemp, "utf-8");
            mmap.put("payUrl", payUrl);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return "QTZ";
    }

    /**
     * 擎天柱回调
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @GetMapping("qtz")
    @ResponseBody
    public AjaxResult getQTZOrder(QTZCallMsg qtzCallMsg) {
        return AjaxResult.success("操作成功");
    }

    /**
     * 擎天柱回调
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("qtz")
    @ResponseBody
    public String updatQTZOrder(QTZCallMsg qtzCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(qtzCallMsg.toString());
        if (!qtzCallMsg.getState().equals("success")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(qtzCallMsg.getMchId());
        searchPayInfo.getParams().put("payerName", "擎天柱支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始签名
        String signTemp = qtzCallMsg.getMchId() + payerInfos.get(0).getApiKey() + qtzCallMsg.getOrderNum() + qtzCallMsg.getAmount();
        boolean b = Md5Utils.vertifySHA256(signTemp, qtzCallMsg.getSign());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatQTZOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(qtzCallMsg.getOrderNum());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到两条相同的数据";
        }
        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Long.valueOf(qtzCallMsg.getAmount())).divide(BigDecimal.valueOf(100L)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 126
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("126")
    @ResponseBody
    public String updat126Order(Z126CallMsg z126CallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(z126CallMsg.toString());
        if (!z126CallMsg.getCallbacks().equals("CODE_SUCCESS")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(z126CallMsg.getAppid());
        searchPayInfo.getParams().put("payerName", "126支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始签名
        String signTemp = "amount=" + z126CallMsg.getAmount() + "&amount_true=" + z126CallMsg.getAmount_true() + "&appid=" + z126CallMsg.getAppid() + "&callbacks="
                + z126CallMsg.getCallbacks() + "&error_url=" + z126CallMsg.getError_url() + "&out_trade_no=" + z126CallMsg.getOut_trade_no()
                + "&out_uid=" + z126CallMsg.getOut_uid() + "&pay_type=" + z126CallMsg.getPay_type() + "&success_url=" + z126CallMsg.getSuccess_url() + "&key=" + payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, z126CallMsg.getSign());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updat126Order验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(z126CallMsg.getOut_trade_no());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到两条相同的数据";
        }
        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(z126CallMsg.getAmount_true())));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation("梦支付中间页面")
    @GetMapping("mzfView/{orderId}")
    public String mzfView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/mzf";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "梦支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }

        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        String stringSignTemp = "pay_amount=" + channelOrder.getAmount() + "&pay_applydate=" + time + "&pay_bankcode=" + businessRate.getPayerPayType() + "&pay_callbackurl=" + callbackUrl + "&pay_memberid=" + businessRate.getPayerBusinessId() + "&pay_notifyurl=" + callbackUrl + "&pay_orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            sign = Md5Utils.androidMD5(stringSignTemp).toUpperCase();
        } catch (Exception e) {
        }
        YhbCallMsg yhbCallMsg = new YhbCallMsg();
        yhbCallMsg.setPay_memberid(businessRate.getPayerBusinessId());
        yhbCallMsg.setPay_orderid(channelOrder.getPtOrderno());
        yhbCallMsg.setPay_applydate(time);
        yhbCallMsg.setPay_bankcode(businessRate.getPayerPayType());
        yhbCallMsg.setPay_notifyurl(callbackUrl);
        yhbCallMsg.setPay_callbackurl(callbackUrl);
        yhbCallMsg.setPay_amount(channelOrder.getAmount());
        yhbCallMsg.setPay_md5sign(sign);
        yhbCallMsg.setPay_productname("收款");
//        stringBuilder.append("&pay_productnum=");
//        stringBuilder.append("&pay_productdesc=");
//        stringBuilder.append("&pay_producturl=");
        mmap.put("yhbCallMsg", yhbCallMsg);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "MZF";
    }

    /**
     * 下游支付商调用的接口,告诉支付中心 订单已经完成了
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("mzf")
    @ResponseBody
    public String updateMzfOrder(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        return updateZYOrder(pddCallMsg, "梦支付");
    }

    @ApiOperation("龙支付中间页面")
    @GetMapping("lzfView/{orderId}")
    public String lzfView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/lzf";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "龙支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }

        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        String stringSignTemp = "pay_amount=" + channelOrder.getAmount() + "&pay_applydate=" + time + "&pay_bankcode=" + businessRate.getPayerPayType() + "&pay_callbackurl=" + callbackUrl + "&pay_memberid=" + businessRate.getPayerBusinessId() + "&pay_notifyurl=" + callbackUrl + "&pay_orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            sign = Md5Utils.androidMD5(stringSignTemp).toUpperCase();
        } catch (Exception e) {
        }
        YhbCallMsg yhbCallMsg = new YhbCallMsg();
        yhbCallMsg.setPay_memberid(businessRate.getPayerBusinessId());
        yhbCallMsg.setPay_orderid(channelOrder.getPtOrderno());
        yhbCallMsg.setPay_applydate(time);
        yhbCallMsg.setPay_bankcode(businessRate.getPayerPayType());
        yhbCallMsg.setPay_notifyurl(callbackUrl);
        yhbCallMsg.setPay_callbackurl(callbackUrl);
        yhbCallMsg.setPay_amount(channelOrder.getAmount());
        yhbCallMsg.setPay_md5sign(sign);
        yhbCallMsg.setPay_productname("收款");
//        stringBuilder.append("&pay_productnum=");
//        stringBuilder.append("&pay_productdesc=");
//        stringBuilder.append("&pay_producturl=");
        mmap.put("yhbCallMsg", yhbCallMsg);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "MZF";
    }

    /**
     * 下游支付商调用的接口,告诉支付中心 订单已经完成了
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("lzf")
    @ResponseBody
    public String updateLzfOrder(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        return updateZYOrder(pddCallMsg, "龙支付");
    }

    @ApiOperation("斗鱼支付中间页面")
    @GetMapping("dyView/{orderId}")
    public String dyView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/dy";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "斗鱼支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }

        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        String stringSignTemp = "pay_amount=" + channelOrder.getAmount() + "&pay_applydate=" + time + "&pay_bankcode=" + businessRate.getPayerPayType() + "&pay_callbackurl=" + callbackUrl + "&pay_memberid=" + businessRate.getPayerBusinessId() + "&pay_notifyurl=" + callbackUrl + "&pay_orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            sign = Md5Utils.androidMD5(stringSignTemp).toUpperCase();
        } catch (Exception e) {
        }
        YhbCallMsg yhbCallMsg = new YhbCallMsg();
        yhbCallMsg.setPay_memberid(businessRate.getPayerBusinessId());
        yhbCallMsg.setPay_orderid(channelOrder.getPtOrderno());
        yhbCallMsg.setPay_applydate(time);
        yhbCallMsg.setPay_bankcode(businessRate.getPayerPayType());
        yhbCallMsg.setPay_notifyurl(callbackUrl);
        yhbCallMsg.setPay_callbackurl(callbackUrl);
        yhbCallMsg.setPay_amount(channelOrder.getAmount());
        yhbCallMsg.setPay_md5sign(sign);
        yhbCallMsg.setPay_productname("收款");
//        stringBuilder.append("&pay_productnum=");
//        stringBuilder.append("&pay_productdesc=");
//        stringBuilder.append("&pay_producturl=");
        mmap.put("yhbCallMsg", yhbCallMsg);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "MZF";
    }

    /**
     * 下游支付商调用的接口,告诉支付中心 订单已经完成了
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("dy")
    @ResponseBody
    public String updateDyOrder(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        return updateZYOrder(pddCallMsg, "斗鱼支付");
    }


    /**
     * 五福
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("wf/{no}")
    @ResponseBody
    public String updatWFOrder(@PathVariable("no") String no, @RequestParam Map<String, Object> params) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(no);
        searchPayInfo.getParams().put("payerName", "五福支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }

        String p = null;
        Iterator<String> iter = params.keySet().iterator();
        while (iter.hasNext()) {
            String key = iter.next();
            if (org.apache.commons.lang3.StringUtils.isNotEmpty(key)) {
                p = key;
            }
        }
        JSONObject jsonObject = JSONObject.parseObject(p);
        String resSign = jsonObject.getString("sign"); // 接口返回sign参数值
        // 开始签名
        try {
            String message = Util.stringToUnicode(jsonObject.getString("message"));
            StringBuffer a = new StringBuffer();
            a.append("{");
            a.append("\"amount\":" + jsonObject.getIntValue("amount") + ",");
            a.append("\"code\":" + "\"" + jsonObject.getString("code") + "\"" + ",");
            a.append("\"inordersn\":" + "\"" + jsonObject.getString("inordersn") + "\"" + ",");
            a.append("\"message\":" + "\"" + message + "\"" + ",");
            a.append("\"outordersn\":" + "\"" + jsonObject.getString("outordersn") + "\"");
            a.append("}");
            log.info("json updatWFOrder:" + a.toString());
            String jsons = a.append(payerInfos.get(0).getApiKey()).toString();
            boolean b = Md5Utils.vertifyAndroidMD5(jsons, resSign.toLowerCase());
            if (b == false) {
                // 如果校验失败要告警 TODO:
                log.error("updatWFOrder验签失败");
                return "验签失败";
            }
            ChannelOrder searchOrder = new ChannelOrder();
            searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
            searchOrder.setPtOrderno(jsonObject.getString("outordersn"));
            List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
            if (channelOrders.size() == 0) {
                return "找不到订单号";
            }
            if (channelOrders.size() > 1) {
                return "找到两条相同的数据";
            }
            channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(jsonObject.getIntValue("amount"))));
            channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
            AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
            log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
            if (0 == (int) ajaxResult.get("code")) {
                return "ok";
            } else {
                return "fail(verify fail)";
            }
        } catch (Exception e) {
            log.info("fail(verify fail)");
            return "fail(verify fail)";
        }
    }

    /**
     * 顶顶回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("dd")
    @ResponseBody
    public String updatDDOrder(DDCallMsg ddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(ddCallMsg.toString());
        if (!ddCallMsg.getStatus().equals("00")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(ddCallMsg.getMerchantNo());
        searchPayInfo.getParams().put("payerName", "顶顶支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始签名
        String signTemp = ddCallMsg.getAmount() + ddCallMsg.getMerchantNo() + ddCallMsg.getMerchantOrderNo() + ddCallMsg.getReal() + ddCallMsg.getStatus() + ddCallMsg.getTransNo() + payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, ddCallMsg.getSign());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatDDOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(ddCallMsg.getMerchantOrderNo());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(ddCallMsg.getReal())).divide(BigDecimal.valueOf(100L)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 鼎新回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("dx")
    @ResponseBody
    public String updatDxOrder(DXCallMsg dxCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(dxCallMsg.toString());
        if (!dxCallMsg.getState().equals("1")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(dxCallMsg.getMerno());
        searchPayInfo.getParams().put("payerName", "鼎新支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始签名
        String signTemp = "mer_order_id=" + dxCallMsg.getMer_order_id() + "&merno=" + dxCallMsg.getMerno() + "&nonce_str=" + dxCallMsg.getNonce_str() + "&order_amt="
                + dxCallMsg.getOrder_amt() + "&order_id=" + dxCallMsg.getOrder_id() + "&state=" + dxCallMsg.getState() + "&key=" + payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, dxCallMsg.getSign().toLowerCase());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatDxOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(dxCallMsg.getMer_order_id());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }
        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(dxCallMsg.getOrder_amt())));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 王者回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("wz/{no}")
    @ResponseBody
    public String updatDxOrder(@PathVariable("no") String no, @RequestBody WZCallMsg wzCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(wzCallMsg.toString());
        if (!wzCallMsg.getCode().equals("S00")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(no);
        searchPayInfo.getParams().put("payerName", "王者支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        // 开始签名
        String signTemp = "actualAmount=" + wzCallMsg.getActualAmount() + "&code=" + wzCallMsg.getCode() + "&merchantOrderNumber=" + wzCallMsg.getMerchantOrderNumber()
                + "&message=" + wzCallMsg.getMessage() + "&orderNumber=" + wzCallMsg.getOrderNumber() + "&paymentMethod=" + wzCallMsg.getPaymentMethod()
                + "&merchantKey=" + payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, wzCallMsg.getSign().toLowerCase());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatWzOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(wzCallMsg.getMerchantOrderNumber());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }
        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(wzCallMsg.getActualAmount())));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "SUCCESS";
        } else {
            return "error";
        }
    }

    @ApiOperation("闪快支付中间页面")
    @GetMapping("skView/{orderId}")
    public String skView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        boolean b = zhiyuView(mmap, orderId, "闪快支付", "sk");
        if (!b) {
            return "openError";
        }
        return "ZY";
    }

    @ApiOperation("亿达支付中间页面")
    @GetMapping("ydView/{orderId}")
    public String ydView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        boolean b = zhiyuView(mmap, orderId, "亿达支付", "yd");
        if (!b) {
            return "openError";
        }
        return "ZY";
    }

    @ApiOperation("荣耀支付中间页面")
    @GetMapping("ryView/{orderId}")
    public String ryView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        boolean b = zhiyuView(mmap, orderId, "荣耀支付", "ry");
        if (!b) {
            return "openError";
        }
        return "ZY";
    }


    /**
     * 知宇视图
     *
     * @param mmap
     * @param orderId
     * @param payer
     * @param callback
     * @return
     */
    private boolean zhiyuView(ModelMap mmap, String orderId, String payer, String callback) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/" + callback;
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", payer);
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return false;
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return false;
        }

        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        String stringSignTemp = "pay_amount=" + channelOrder.getAmount() + "&pay_applydate=" + time + "&pay_bankcode=" + businessRate.getPayerPayType()
                + "&pay_callbackurl=" + callbackUrl + "&pay_memberid=" + businessRate.getPayerBusinessId() + "&pay_notifyurl="
                + callbackUrl + "&pay_orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            log.info("skView:" + stringSignTemp);
            sign = Md5Utils.androidMD5(stringSignTemp).toUpperCase();
            log.info("kskView加密结果:" + sign);
        } catch (Exception e) {
        }
        YhbCallMsg kxCallMsg = new YhbCallMsg();
        kxCallMsg.setPay_amount(channelOrder.getAmount());
        kxCallMsg.setPay_applydate(time);
        kxCallMsg.setPay_bankcode(businessRate.getPayerPayType());
        kxCallMsg.setPay_callbackurl(callbackUrl);
        kxCallMsg.setPay_memberid(businessRate.getPayerBusinessId());
        kxCallMsg.setPay_notifyurl(callbackUrl);
        kxCallMsg.setPay_orderid(channelOrder.getPtOrderno());
        kxCallMsg.setPay_md5sign(sign);
        kxCallMsg.setPay_productdesc("");
        kxCallMsg.setPay_productname("收款");
        kxCallMsg.setPay_productnum("");
        kxCallMsg.setPay_producturl("");
        mmap.put("kxCallMsg", kxCallMsg);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return true;
    }

    /**
     * 闪快支付
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("sk")
    @ResponseBody
    public String updatSKrder(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        return updateZYOrder(pddCallMsg, "闪快支付");
    }

    /**
     * 闪快支付
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("yd")
    @ResponseBody
    public String updatYDrder(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        return updateZYOrder(pddCallMsg, "亿达支付");
    }

    /**
     * 闪快支付
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("ry")
    @ResponseBody
    public String updatRYOrder(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        return updateZYOrder(pddCallMsg, "荣耀支付");
    }

    @ApiOperation("柚子支付中间页面")
    @GetMapping("youziView/{orderId}")
    public String dingshengView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/youzi";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "柚子支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }
        HashMap<String, String> map = new HashMap<>();
        map.put("mchId", businessRate.getPayerBusinessId());
        map.put("appId", "947f0c75054647dba2f6ee1946af844e");
        map.put("mchOrderNo", channelOrder.getPtOrderno());
        map.put("productId", businessRate.getPayerPayType());
        String amount = (channelOrder.getAmount().multiply(BigDecimal.valueOf(100L)) + "").replace(".00", "").replace(".0", "");
        map.put("amount", amount);
        map.put("notifyUrl", callbackUrl);
        map.put("subject", "快捷支付");
        map.put("body", "快捷支付");
        map.put("extra", "{\"bank\":8051}");
        String sign = "";
        try {
            String signStr = Util.sortKey(map);
            sign = Md5Utils.androidMD5(signStr + "&key=" + payerInfos.get(0).getApiKey()).toUpperCase();
        } catch (Exception e) {
        }
        DingShengCallMsg yhbCallMsg = new DingShengCallMsg();
        yhbCallMsg.setMchId(map.get("mchId"));
        yhbCallMsg.setAppId(map.get("appId"));
        yhbCallMsg.setMchOrderNo(map.get("mchOrderNo"));
        yhbCallMsg.setProductId(map.get("productId"));
        yhbCallMsg.setAmount(amount);
        yhbCallMsg.setNotifyUrl(map.get("notifyUrl"));
        yhbCallMsg.setSubject(map.get("subject"));
        yhbCallMsg.setBody(map.get("body"));
        yhbCallMsg.setExtra(map.get("extra"));
        yhbCallMsg.setSign(sign);
        mmap.put("yhbCallMsg", yhbCallMsg);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "DS";
    }

    /**
     * 柚子支付
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("youzi")
    @ResponseBody
    public String updatDingshengOrder(DingShengCallMsg dingShengCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(dingShengCallMsg.toString());
        if (!dingShengCallMsg.getStatus().equals("2") && !dingShengCallMsg.getStatus().equals("3")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(dingShengCallMsg.getMchId());
        searchPayInfo.getParams().put("payerName", "柚子支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        // 开始签名
        HashMap<String, String> map = new HashMap<>();
        map.put("payOrderId", dingShengCallMsg.getPayOrderId());
        map.put("mchId", dingShengCallMsg.getMchId());
        map.put("appId", dingShengCallMsg.getAppId());
        map.put("productId", dingShengCallMsg.getProductId());
        map.put("mchOrderNo", dingShengCallMsg.getMchOrderNo());
        map.put("amount", dingShengCallMsg.getAmount());
        map.put("income", dingShengCallMsg.getIncome());
        map.put("status", dingShengCallMsg.getStatus());
        map.put("channelOrderNo", dingShengCallMsg.getChannelOrderNo());
        map.put("paySuccTime", dingShengCallMsg.getPaySuccTime());
        map.put("backType", dingShengCallMsg.getBackType());
        String signTemp = Util.sortKey(map);
//        String signTemp = "actualAmount="+wzCallMsg.getActualAmount()+"&code="+wzCallMsg.getCode()+"&merchantOrderNumber="+wzCallMsg.getMerchantOrderNumber()
//                +"&message="+wzCallMsg.getMessage()+"&orderNumber="+wzCallMsg.getOrderNumber()+"&paymentMethod="+wzCallMsg.getPaymentMethod()
//                +"&merchantKey="+ payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp + "&key=" + payerInfos.get(0).getApiKey(), dingShengCallMsg.getSign().toLowerCase());
        if (b == false) {
            // 如果校验失败要告警
            log.error("updatDingshengOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(dingShengCallMsg.getMchOrderNo());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }
        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Long.valueOf(dingShengCallMsg.getAmount())).divide(BigDecimal.valueOf(100L)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 先锋银联
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @GetMapping("xf")
    @ResponseBody
    public String updatXfOrder(XFCallMsg xfCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(xfCallMsg.toString());
        if (!xfCallMsg.getStatus().equals("1")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(xfCallMsg.getMch_uid());
        searchPayInfo.getParams().put("payerName", "先锋银联");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始签名
        String sortParam = "mch_uid=" + xfCallMsg.getMch_uid() + "&out_trade_no=" + xfCallMsg.getOut_trade_no() + "&pay_type=" + xfCallMsg.getPay_type()
                + "&paytime=" + xfCallMsg.getPaytime() + "&real_fee=" + xfCallMsg.getReal_fee()
                + "&status=" + xfCallMsg.getStatus() + "&timestamp=" + xfCallMsg.getTimestamp() + "&total_fee=" + xfCallMsg.getTotal_fee() + "&transaction_id=" + xfCallMsg.getTransaction_id();
        String signTemp = sortParam + payerInfos.get(0).getApiKey();
//        String signTemp = "actualAmount="+xfCallMsg.getReal_fee()+"&code="+xfCallMsg.get+"&merchantOrderNumber="+wzCallMsg.getMerchantOrderNumber()
//                +"&message="+wzCallMsg.getMessage()+"&orderNumber="+wzCallMsg.getOrderNumber()+"&paymentMethod="+wzCallMsg.getPaymentMethod()
//                +"&merchantKey="+ payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, xfCallMsg.getSign().toLowerCase());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatXfOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(xfCallMsg.getOut_trade_no());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }
        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(xfCallMsg.getReal_fee())));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }


    /**
     * 乘风回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("cf")
    @ResponseBody
    public String updatCfOrder(DDCallMsg ddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(ddCallMsg.toString());
        if (!ddCallMsg.getStatus().equals("00")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(ddCallMsg.getMerchantNo());
        searchPayInfo.getParams().put("payerName", "乘风支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始签名
        String signTemp = ddCallMsg.getAmount() + ddCallMsg.getMerchantNo() + ddCallMsg.getMerchantOrderNo() + ddCallMsg.getReal() + ddCallMsg.getStatus() + ddCallMsg.getTransNo() + payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, ddCallMsg.getSign());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatDDOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(ddCallMsg.getMerchantOrderNo());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(ddCallMsg.getReal())).divide(BigDecimal.valueOf(100L)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation("微富支付中间页面")
    @GetMapping("weifuView/{orderId}")
    public String weifuView(@PathVariable("orderId") String orderId, ModelMap mmap) {

        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/weifu/" + channelOrder.getPtOrderno();
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "微富支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }

        // 查询
        String ip = ServletUtils.getRequest().getRemoteHost();
        String signStr1 = "BuCode=" + businessRate.getPayerBusinessId() + "&IP=" + ip;
        String sign1 = "";
        try {
            sign1 = Md5Utils.androidMD5(signStr1 + "&Key=" + payerInfos.get(0).getApiKey());
        } catch (Exception e) {
        }
        RestTemplate restTemplate1 = new RestTemplate();
        HttpHeaders headers1 = new HttpHeaders();
        headers1.setContentType(MediaType.APPLICATION_JSON_UTF8);
        HttpEntity entity1 = new HttpEntity(headers1);
        log.info("查询微富是否有码：" + signStr1);
        String body1 = restTemplate1.exchange(payerInfo.getServiceUrl() + "/qr/count?" + signStr1 + "&Sign=" + sign1, HttpMethod.GET, entity1, String.class).getBody();
        log.info("查询微富是否有码：" + body1);
        JSONObject resultO1 = JSONObject.parseObject(body1);
        boolean b = resultO1.getBooleanValue("status");
        if (!b) {
            mmap.put("channelOrder", channelOrder);
            mmap.put("qrcode", "暂时没码了，请稍后重试");
            return "openOutTime";
        }
        String signStr = "BuCode=" + businessRate.getPayerBusinessId() + "&OrderId=" + channelOrder.getPtOrderno() + "&PayChannel=" + businessRate.getPayerPayType() + "&OrderAccount=Guest001&Amount=" + channelOrder.getAmount();
        String sign = "";
        try {
            sign = Md5Utils.androidMD5(signStr + "&Key=" + payerInfos.get(0).getApiKey());
        } catch (Exception e) {
        }
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("BuCode", businessRate.getPayerBusinessId());
        jsonObject.put("OrderId", channelOrder.getPtOrderno());
        jsonObject.put("PayChannel", businessRate.getPayerPayType());
        jsonObject.put("OrderAccount", "Guest001");
        jsonObject.put("Amount", channelOrder.getAmount() + "");
        jsonObject.put("NotifyURL", callbackUrl);
        jsonObject.put("IP", ip);
        jsonObject.put("Sign", sign);
        log.info("weifuView body:" + jsonObject.toJSONString());
        HttpEntity entity = new HttpEntity(jsonObject.toJSONString(), headers);
        String body = restTemplate.exchange(payerInfo.getServiceUrl() + "/deposit/apply/", HttpMethod.POST, entity, String.class).getBody();
        log.info("weifuView body:" + body);
        JSONObject resultO = JSONObject.parseObject(body);
        JSONObject dataResult = resultO.getJSONObject("data");
        String redirectURL = dataResult.getString("redirectURL");
        mmap.put("url", redirectURL.replace("<!doctype html><html lang=\"zh-cn\"><head><meta charset=\"utf-8\"><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title></title><style> </style></head><body>", "").replace("</body></html>", ""));
        return "WEIFU";
    }

    /**
     * 微富回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @GetMapping("weifu/{orderId}")
    @ResponseBody
    public JSONObject updatWeifuOrder(@PathVariable("orderId") String orderId, String BuCode, String TransId, String Amount, String Status, String Sign) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        JSONObject jsonObject = new JSONObject();
        log.info("bucode:" + BuCode + ";transid:" + TransId + ";Amount=" + Amount + ";status=" + Status + ";sign=" + Sign);
        if (!Status.equals("true")) {
            jsonObject.put("status", false);
            jsonObject.put("err_msg", "失败");
            return jsonObject;
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(BuCode);
        searchPayInfo.getParams().put("payerName", "微富支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            jsonObject.put("status", false);
            jsonObject.put("err_msg", "找不到商户");
            return jsonObject;
        }
        if (payerInfos.size() > 1) {
            jsonObject.put("status", false);
            jsonObject.put("err_msg", "找到多个商户");
            return jsonObject;
        }
        String signTemp = "BuCode=" + BuCode + "&TransId=" + TransId + "&Amount=" + Amount + "&Status=" + Status + "&Key=" + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, Sign);
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatWeifuOrder验签失败");
            jsonObject.put("status", false);
            jsonObject.put("err_msg", "验签失败");
            return jsonObject;
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(orderId);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            jsonObject.put("status", false);
            jsonObject.put("err_msg", "找不到订单号");
            return jsonObject;
        }
        if (channelOrders.size() > 1) {
            jsonObject.put("status", false);
            jsonObject.put("err_msg", "找到多条相同的数据");
            return jsonObject;
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            jsonObject.put("status", false);
            jsonObject.put("err_msg", "单子已经过期或者已经成功,请勿重复更新");
            return jsonObject;
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(Amount)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            jsonObject.put("status", true);
            jsonObject.put("err_msg", "success");
            return jsonObject;
        } else {
            jsonObject.put("status", false);
            jsonObject.put("err_msg", "error");
            return jsonObject;
        }
    }


    /**
     * 重阳回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("chongyang")
    @ResponseBody
    public String updatChongYangOrder(String data) {
        java.util.Base64.Decoder decoder = java.util.Base64.getDecoder();
        HashMap<String, String> hashMap = new HashMap<>();
        JSONObject jsonObject = null;
        try {
            String dataStr = new String(decoder.decode(data), "UTF-8");
            log.info("updatChongYangOrder:" + dataStr);
            jsonObject = JSONObject.parseObject(dataStr);
            Iterator<String> iterator = jsonObject.keySet().iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                if (key.equals("sign")) {
                    continue;
                }
                hashMap.put(key, jsonObject.getString(key));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        if (!hashMap.get("status").equals("1")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(hashMap.get("appid"));
        searchPayInfo.getParams().put("payerName", "重阳支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始签名
        hashMap.put("appkey", payerInfos.get(0).getApiKey());
        String signStr = Util.sortKey(hashMap);
        boolean b = Md5Utils.vertifyAndroidMD5(signStr, jsonObject.getString("sign"));
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("chongyang验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(hashMap.get("orderid"));
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(hashMap.get("realmoney"))));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 真有钱支付
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("zyq")
    @ResponseBody
    public String updatZYQOrder(String merId, String orderId, String sysOrderId, String desc, String orderAmt, String status, String attch, String nonceStr, String sign) {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("merId", merId);
        hashMap.put("orderId", orderId);
        hashMap.put("sysOrderId", sysOrderId);
        hashMap.put("desc", desc);
        hashMap.put("orderAmt", orderAmt);
        hashMap.put("status", status);
//        hashMap.put("attch",attch);
        hashMap.put("nonceStr", nonceStr);
        log.info("真有钱：" + hashMap.toString());
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        if (!hashMap.get("status").equals("1")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(merId);
        searchPayInfo.getParams().put("payerName", "真有钱支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        // 开始解码


        // 开始签名
//        hashMap.put("appkey",payerInfos.get(0).getApiKey());
        String signStr = Util.sortKey(hashMap);
//        String md5Sign = Md5Utils.androidMD5(signStr + "&key=" + payerInfos.get(0).getApiKey()).toUpperCase();
//        log.info("原始字符串：" + signStr + "；通过计算得到的MD5：" + md5Sign);
//        boolean b = SHA256WithRSAUtils.buildRSAverifyByPublicKey(md5Sign, payerInfos.get(0).getPublicKey(), sign);
        boolean b = Md5Utils.vertifyAndroidMD5(signStr + "&key=" + payerInfos.get(0).getApiKey(), sign.toLowerCase());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("真有钱验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(orderId);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(orderAmt)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation("全荣支付中间页面")
    @GetMapping("quanrongView/{orderId}")
    public String quanrongView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/quanrong";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "全荣支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }
        String returnUrl = channelOrder.getReturnUrl();
        if (returnUrl == null || "".equals(returnUrl)) {
            returnUrl = payConfig.getPayCenterHost() + "/pay/orderSuccess/" + channelOrder.getOrderId();
        }
        long sendTime = System.currentTimeMillis() / 1000;
        String stringSignTemp = "merchant=" + businessRate.getPayerBusinessId() + "&qrtype=" + businessRate.getPayerPayType() + "&customno=" + channelOrder.getPtOrderno() + "&money=" + channelOrder.getAmount()
                + "&sendtime=" + sendTime
                + "&notifyurl=" + callbackUrl + "&backurl=" + returnUrl + "&risklevel=";
//        String stringSignTemp = "pay_amount=" + channelOrder.getAmount() + "&pay_applydate=" + time + "&pay_bankcode=" + businessRate.getPayerPayType() + "&pay_callbackurl=" + callbackUrl + "&pay_memberid=" + businessRate.getPayerBusinessId() + "&pay_notifyurl=" + callbackUrl + "&pay_orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            sign = Md5Utils.androidMD5(stringSignTemp + payerInfos.get(0).getApiKey());
        } catch (Exception e) {
        }
        RYCallMsg yhbCallMsg = new RYCallMsg();
        yhbCallMsg.setMerchant(businessRate.getPayerBusinessId());
        yhbCallMsg.setQrtype(businessRate.getPayerPayType());
        yhbCallMsg.setCustomno(channelOrder.getPtOrderno());
        yhbCallMsg.setMoney(channelOrder.getAmount() + "");
        yhbCallMsg.setSendtime(sendTime + "");
        yhbCallMsg.setNotifyurl(callbackUrl);
        yhbCallMsg.setBackurl(returnUrl);
        yhbCallMsg.setSign(sign);
//        stringBuilder.append("&pay_productnum=");
//        stringBuilder.append("&pay_productdesc=");
//        stringBuilder.append("&pay_producturl=");
        mmap.put("yhbCallMsg", yhbCallMsg);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "QUANRONG";
    }

    /**
     * 全荣支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("quanrong")
    @ResponseBody
    public String updatQuanRongOrder(RYCallMsg ryCallMsg) {

        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info("quanrong:" + ryCallMsg.toString());
        if (!ryCallMsg.getState().equals("1")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(ryCallMsg.getMerchant());
        searchPayInfo.getParams().put("payerName", "全荣支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        if (!ServletUtils.getRequest().getRemoteHost().equals(payerInfo.getServiceIp())) {
            return "非法IP";
        }

        String signTemp = "merchant=" + ryCallMsg.getMerchant() + "&merchant_money=" + ryCallMsg.getMerchant_money() + "&qrtype=" + ryCallMsg.getQrtype() + "&customno=" + ryCallMsg.getCustomno()
                + "&sendtime=" + ryCallMsg.getSendtime() + "&orderno=" + ryCallMsg.getOrderno()
                + "&money=" + ryCallMsg.getMoney() + "&paytime=" + ryCallMsg.getPaytime()
                + "&state=" + ryCallMsg.getState() + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, ryCallMsg.getSign());
        if (b == false) {
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(ryCallMsg.getCustomno());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(ryCallMsg.getMoney())));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation("林府银联中间页面")
    @GetMapping("linfuView/{orderId}")
    public String linfuView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/linfu";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "林府银联");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }
        String returnUrl = channelOrder.getReturnUrl();
        if (returnUrl == null || "".equals(returnUrl)) {
            returnUrl = payConfig.getPayCenterHost() + "/pay/orderSuccess/" + channelOrder.getOrderId();
        }
        String timestamp = System.currentTimeMillis() / 1000 + "";
        mmap.put("order_no", channelOrder.getPtOrderno());
        mmap.put("orderId", channelOrder.getOrderId());
        mmap.put("amount", channelOrder.getAmount());
        mmap.put("timestamp", timestamp);
        mmap.put("payUri", payConfig.getPayCenterHost() + "/callback/linfuView2");
        return "LINFU";
    }

    @ApiOperation("林府银联中间页面")
    @PostMapping("linfuView2")
    public String linfuView(String orderId, String bank, ModelMap mmap) {
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "林府银联");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }
        String timestamp = System.currentTimeMillis() / 1000 + "";
        String signStr = channelOrder.getPtOrderno() + channelOrder.getAmount() + bank + timestamp + "linfu666";
        String sign = Md5Utils.androidMD5(signStr).toUpperCase();
        mmap.put("order_no", channelOrder.getPtOrderno());
        mmap.put("sign", sign);
        mmap.put("bank", bank);
        mmap.put("amount", channelOrder.getAmount());
        mmap.put("timestamp", timestamp);
        String[] payUris = payerInfo.getServiceUrl().split(",");
        String payUri = payUris[new Random().nextInt(payUris.length)];
        mmap.put("payUri", payUri);
        return "LINFU2";
    }

    /**
     * 林府银联
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("linfu")
    @ResponseBody
    public String updatLinfuOrder(String sign, String order_no, String amount, String create_time, String alipay_order_id, String pay_status, String instruction_id, String payer_inst_name, String payer_card_no, String pay_amount, String pay_time, String pay_title) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info("sign=" + sign + "&order_no=" + order_no + "&amount=" + amount + "&create_time=" + create_time + "&alipay_order_id=" + alipay_order_id
                + "&pay_status=" + pay_status + "&instruction_id=" + instruction_id + "&payer_inst_name=" + payer_inst_name + "&payer_card_no=" + payer_card_no
                + "&pay_amount=" + pay_amount + "&pay_time=" + pay_time + "&pay_title=" + pay_title);
// "$order_no|$amount|$create_time|$alipay_order_id|$pay_status|$instruction_id|$payer_inst_name|$payer_card_no|$pay_amount|$pay_time|$pay_title|$key"
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.getParams().put("payerName", "林府银联");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        log.info("当前前期林府银联回调ip：" + ServletUtils.getRequest().getRemoteHost());
        if (!ServletUtils.getRequest().getRemoteHost().equals(payerInfo.getServiceIp())) {
            log.info("非法请求");
            return "非法请求";
        }

        String signTemp = order_no + amount + create_time + alipay_order_id + pay_status + instruction_id + payer_inst_name + payer_card_no + pay_amount + pay_time + pay_title + payerInfos.get(0).getApiKey();
        // 开始签名
        log.info("验签字符串：" + signTemp);
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
//        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, sign.toLowerCase());
//        if (b == false) {
//            log.info("验签失败");
//            return "验签失败";
//        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(order_no);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(pay_amount)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation("笨鸟支付中间页面")
    @GetMapping("benniaoView/{orderId}")
    public String benniaoView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/benniao";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "笨鸟支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }
        String returnUrl = channelOrder.getReturnUrl();
        if (returnUrl == null || "".equals(returnUrl)) {
            returnUrl = payConfig.getPayCenterHost() + "/pay/orderSuccess/" + channelOrder.getOrderId();
        }
        long sendTime = System.currentTimeMillis();
        String stringSignTemp = "businessId=" + payerInfos.get(0).getBusinessNo() + "&payType=" + businessRate.getPayerPayType()
                + "&childOrderno=" + channelOrder.getPtOrderno() + "&amount=" + channelOrder.getAmount() + "&time=" + sendTime;
//        String stringSignTemp = "pay_amount=" + channelOrder.getAmount() + "&pay_applydate=" + time + "&pay_bankcode=" + businessRate.getPayerPayType() + "&pay_callbackurl=" + callbackUrl + "&pay_memberid=" + businessRate.getPayerBusinessId() + "&pay_notifyurl=" + callbackUrl + "&pay_orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            log.info("笨鸟加密字符串：" + stringSignTemp);
            sign = Md5Utils.androidMD5(stringSignTemp + "&" + payerInfos.get(0).getApiKey());
        } catch (Exception e) {
        }
        channelOrder.setServerUrl(callbackUrl);
        channelOrder.setBusinessId(Long.valueOf(payerInfos.get(0).getBusinessNo()));
        channelOrder.setReturnUrl(returnUrl);
        channelOrder.setChildOrderno(channelOrder.getPtOrderno());
        mmap.put("sign", sign);
        mmap.put("time", sendTime);
        mmap.put("channelOrder", channelOrder);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "BENNIAO";
    }

    @ApiOperation("笨鸟支付中间页面")
    @GetMapping("benniaoJSON/{orderId}")
    public String benniaoJSON(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/benniao";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "笨鸟支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }
        String returnUrl = channelOrder.getReturnUrl();
        if (returnUrl == null || "".equals(returnUrl)) {
            returnUrl = payConfig.getPayCenterHost() + "/pay/orderSuccess/" + channelOrder.getOrderId();
        }
        long sendTime = System.currentTimeMillis();
        String stringSignTemp = "businessId=" + payerInfos.get(0).getBusinessNo() + "&payType=" + businessRate.getPayerPayType()
                + "&childOrderno=" + channelOrder.getPtOrderno() + "&amount=" + channelOrder.getAmount() + "&time=" + sendTime;
//        String stringSignTemp = "pay_amount=" + channelOrder.getAmount() + "&pay_applydate=" + time + "&pay_bankcode=" + businessRate.getPayerPayType() + "&pay_callbackurl=" + callbackUrl + "&pay_memberid=" + businessRate.getPayerBusinessId() + "&pay_notifyurl=" + callbackUrl + "&pay_orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            log.info("笨鸟加密字符串：" + stringSignTemp);
            sign = Md5Utils.androidMD5(stringSignTemp + "&" + payerInfos.get(0).getApiKey());
        } catch (Exception e) {
        }
        channelOrder.setServerUrl(callbackUrl);
        channelOrder.setBusinessId(Long.valueOf(payerInfos.get(0).getBusinessNo()));
        channelOrder.setReturnUrl(returnUrl);
        channelOrder.setChildOrderno(channelOrder.getPtOrderno());
        mmap.put("sign", sign);
        mmap.put("time", sendTime);
        mmap.put("channelOrder", channelOrder);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "BENNIAO";
    }

    /**
     * 笨鸟支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("benniao")
    @ResponseBody
    public String updatBenniaoOrder(ChannelOrder callOrder, String time, String sign) {

        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info("benniao:" + callOrder.toString());
        if (!callOrder.getOrderStatus().equals("1") && !callOrder.getOrderStatus().equals("2") && !callOrder.getOrderStatus().equals("3")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(callOrder.getBusinessId() + "");
        searchPayInfo.getParams().put("payerName", "笨鸟支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        if (!ServletUtils.getRequest().getRemoteHost().equals(payerInfo.getServiceIp())) {
            return "非法IP";
        }

        String signTemp = "childOrderno=" + callOrder.getChildOrderno() + "&payAmount=" + callOrder.getPayAmount() + "&orderStatus=" + callOrder.getOrderStatus() + "&time=" + time + "&" + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, sign);
        if (b == false) {
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(callOrder.getChildOrderno());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(callOrder.getPayAmount());
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 牛牛支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("niuniu")
    @ResponseBody
    public String updatNiuNiuOrder(String callbacks, String appid, String pay_type, String success_url, String error_url, String out_trade_no, String amount, String sign, String amount_true, String out_uid) {

        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("callbacks", callbacks);
        hashMap.put("appid", appid);
        hashMap.put("pay_type", pay_type);
        hashMap.put("success_url", success_url);
        hashMap.put("error_url", error_url);
        hashMap.put("out_trade_no", out_trade_no);
        hashMap.put("amount", amount);
        hashMap.put("amount_true", amount_true);
        hashMap.put("out_uid", out_uid);
        log.info("niuniu:" + Util.sortKey(hashMap));
        if (!callbacks.equals("CODE_SUCCESS")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(appid);
        searchPayInfo.getParams().put("payerName", "牛牛支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        if (!ServletUtils.getRequest().getRemoteHost().equals(payerInfo.getServiceIp())) {
            log.info("非法IP");
            return "非法IP";
        }

        String signTemp = Util.sortKey(hashMap) + "&key=" + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, sign.toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(out_trade_no);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(amount_true)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 鑫和支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("xinhe")
    @ResponseBody
    public String updatXinHeOrder(String result, String code, String msg, String mer_id, String businessnumber, String status, String transactiondate, String sign, String amount, String real_amount, String transactiontype, String inputdate, String remark, String sign_type) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("result", result);
        hashMap.put("code", code);
        hashMap.put("msg", msg);
        hashMap.put("mer_id", mer_id);
        hashMap.put("businessnumber", businessnumber);
        hashMap.put("status", status);
        hashMap.put("transactiondate", transactiondate);
        hashMap.put("amount", amount);
        hashMap.put("real_amount", real_amount);
        hashMap.put("transactiontype", transactiontype);
        hashMap.put("inputdate", inputdate);
        hashMap.put("remark", remark);
        log.info("xinhe:" + Util.sortKey(hashMap));
        if (!status.equals("成功")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
//        searchPayInfo.setBusinessNo(mer_id);
        searchPayInfo.getParams().put("payerName", "鑫和支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }
        String signTemp = Util.sortKey(hashMap) + "&" + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, sign.toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(businessnumber);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(channelOrders.get(0).getAmount());
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }


    /**
     * 乐购乐付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("legou")
    @ResponseBody
    public String updatLeGouOrder(String callbacks, String appid, String pay_type, String success_url, String error_url, String out_trade_no, String amount, String sign, String amount_true, String out_uid) {

        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("callbacks", callbacks);
        hashMap.put("appid", appid);
        hashMap.put("pay_type", pay_type);
        hashMap.put("success_url", success_url);
        hashMap.put("error_url", error_url);
        hashMap.put("out_trade_no", out_trade_no);
        hashMap.put("amount", amount);
        hashMap.put("amount_true", amount_true);
        hashMap.put("out_uid", out_uid);
        log.info("niuniu:" + Util.sortKey(hashMap));
        if (!callbacks.equals("CODE_SUCCESS")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(appid);
        searchPayInfo.getParams().put("payerName", "乐购乐付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        if (!ServletUtils.getRequest().getRemoteHost().equals(payerInfo.getServiceIp())) {
            log.info("非法IP");
            return "非法IP";
        }

        String signTemp = Util.sortKey(hashMap) + "&key=" + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, sign.toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(out_trade_no);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(amount_true)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation("智汇通B支付支付中间页面")
    @GetMapping("zhtView/{orderId}")
    public String zhtView(@PathVariable("orderId") String orderId, ModelMap mmap) {

        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "智汇通B支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/zht/"+businessRate.getPayerBusinessId();
        String returnUrl = channelOrder.getReturnUrl();
        if (returnUrl == null || "".equals(returnUrl)) {
            returnUrl = payConfig.getPayCenterHost() + "/pay/orderSuccess/" + channelOrder.getOrderId();
        }
        DecimalFormat fnum = new DecimalFormat("##0.00");
        String dd = fnum.format(channelOrder.getAmount());
//        String sign = "";
        try {
//            HashMap<String,String> hashMap = new HashMap<>();
//            hashMap.put("id",businessRate.getPayerBusinessId());
//            hashMap.put("pay_type",businessRate.getPayerPayType());
//            hashMap.put("price",dd);
//            hashMap.put("format","html");
//            hashMap.put("out_trade_no",channelOrder.getPtOrderno());
//            hashMap.put("notify_url",URLEncoder.encode(callbackUrl,"UTF-8"));
//            hashMap.put("return_url",URLEncoder.encode(returnUrl,"UTF-8"));
//            hashMap.put("pay_user_id",channelOrder.getPtOrderno());
//            String sortParam = Util.sortKey(hashMap);
//            sign = Md5Utils.androidMD5(sortParam + payerInfos.get(0).getApiKey());
//            log.info("智汇通B支付md5："+ sortParam);
//            String url =  payerInfo.getServiceUrl() + "?"+sortParam+"&sign="+sign;
//            log.info("智汇通B支付url："+ url);
//            mmap.put("payUri", url);



            String key = payerInfos.get(0).getApiKey();
            String id=businessRate.getPayerBusinessId();
            String notify_url=callbackUrl;
            String out_trade_no=channelOrder.getPtOrderno();
            String pay_type=businessRate.getPayerPayType();
            String pay_user_id=channelOrder.getPtOrderno();
            String price=dd;

            //按照字符排序后拼接+key
            String temp_sign = "id="+id+"&notify_url="+notify_url+"&out_trade_no="+out_trade_no+"&pay_type="+pay_type+"&pay_user_id="+pay_user_id+"&price="+price+"&return_url="+returnUrl+key;

            //对每个参数的值进行URLEncoder
            String jump_url = "id="+ URLEncoder.encode(id)+"&notify_url="+ URLEncoder.encode(notify_url)+"&out_trade_no="+URLEncoder.encode(out_trade_no)+"&pay_type="+URLEncoder.encode(pay_type)+"&pay_user_id="+URLEncoder.encode(pay_user_id)+"&price="+URLEncoder.encode(price)+"&return_url="+URLEncoder.encode(returnUrl);
            byte[] secretBytes = null;
            try {
                secretBytes = MessageDigest.getInstance("md5").digest(
                        temp_sign.getBytes());
            } catch (NoSuchAlgorithmException e) {
                throw new RuntimeException("没有这个md5算法！");
            }
            String md5code = new BigInteger(1, secretBytes).toString(16);
            for (int i = 0; i < 32 - md5code.length(); i++) {
                md5code = "0" + md5code;
            }
            System.out.println(md5code);

            //生成请求的链接地址
            jump_url = payerInfo.getServiceUrl() + "?" + jump_url+"&format=html&sign="+md5code;
            mmap.put("payUri", jump_url);
        } catch (Exception e) {
        }
        return "ZHT";
    }

    /**
     * 智汇通B支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("zht/{businessId}")
    @ResponseBody
    public String updatZHTOrder(@PathVariable("businessId") String businessId,String pay_time,String order_no, String order_price, String real_price, String pay_no, String out_trade_no, String param ,String sign) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("order_no", order_no);
        hashMap.put("order_price", order_price);
        hashMap.put("real_price", real_price);
        hashMap.put("pay_no", pay_no);
        hashMap.put("out_trade_no", out_trade_no);
        if(pay_time !=null && !pay_time.equals("")){
            hashMap.put("pay_time", pay_time);
//        hashMap.put("param", param)
        };
        log.info("updatZHTOrder:" + Util.sortKey(hashMap));
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessId);
        searchPayInfo.getParams().put("payerName", "智汇通B支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        if (!ServletUtils.getRequest().getRemoteHost().equals(payerInfo.getServiceIp())) {
            log.info("非法IP");
            return "非法IP";
        }

        String signTemp = Util.sortKey(hashMap) + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, sign.toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(out_trade_no);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(real_price)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success".toUpperCase();
        } else {
            return "error";
        }
    }

    /**
     * 大师支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("dashi")
    @ResponseBody
    public String updatDaShiOrder(String fxid,String fxddh,String fxorder,String fxdesc,String fxfee,String fxattch,String fxstatus,String fxtime,String fxsign) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info("dashi:fxid="+fxid+"&fxddh="+fxddh+"&fxorder="+fxorder+"&fxdesc="+fxdesc+"&fxfee="+fxfee+"&fxattch="+fxattch+"&fxstatus="+fxstatus+"&fxtime="+fxtime+"&fxsign="+fxsign);
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(fxid);
        searchPayInfo.getParams().put("payerName", "大师支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        String signTemp = "fxstatus="+fxstatus+"&fxid="+fxid +"&fxddh="+fxddh+"&fxfee="+fxfee+"&"+ payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, fxsign);
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(fxddh);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(fxfee)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success".toUpperCase();
        } else {
            return "error";
        }
    }

    /**
     * 帝国支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("diguo")
    @ResponseBody
    public String updatDiGuoOrder(String result_code,String transaction_id,String trade_id,String mch_id,String sign,String sign_type,String fee,String amount_fee,String pay_type,String create_time,String confirm_time,String paid_time,String attach) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info("updatDiGuoOrder:result_code="+result_code+"&transaction_id="+transaction_id+"&trade_id="+trade_id+
                "&mch_id="+mch_id+"&sign="+sign+"&sign_type="+sign_type+"&fee="+fee+"&amount_fee="+amount_fee+"&pay_type="+pay_type+"&create_time="+create_time+"&confirm_time="+confirm_time+"&paid_time="+paid_time+"&attach="+attach);
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(mch_id);
        searchPayInfo.getParams().put("payerName", "帝国支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("result_code", result_code);
        hashMap.put("transaction_id", transaction_id);
        hashMap.put("trade_id", trade_id);
        hashMap.put("mch_id", mch_id);
        hashMap.put("sign_type", sign_type);
        hashMap.put("fee", fee);
        hashMap.put("amount_fee", amount_fee);
        hashMap.put("pay_type", pay_type);
        hashMap.put("create_time", create_time);
        hashMap.put("confirm_time", confirm_time);
        if(paid_time !=null && !paid_time.equals("")){
            hashMap.put("paid_time", paid_time);
        };
        log.info("updatZHTOrder:" + Util.sortKey(hashMap));

        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        String md5Str = payerInfos.get(0).getApiKey()+Util.sortKey(hashMap)+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(md5Str, sign.toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(trade_id);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(amount_fee)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "ok".toUpperCase();
        } else {
            return "error";
        }
    }

    /**
     * 牛牛支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("xinniuniu")
    @ResponseBody
    public String updatXinNiuNiuOrder(String amount, String bankCode, String outOrderNo, String extend, String responseMsg, String goodsName, String mchId, String sign, String responseState, String orderNo, String payTime, String signType) {

        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("amount", amount);
        hashMap.put("bankCode", bankCode);
        hashMap.put("outOrderNo", outOrderNo);
        hashMap.put("extend", extend);
        hashMap.put("responseMsg", responseMsg);
        hashMap.put("goodsName", goodsName);
        hashMap.put("amount", amount);
        hashMap.put("mchId", mchId);
        hashMap.put("responseState", responseState);
        hashMap.put("orderNo", orderNo);
        hashMap.put("payTime", payTime);
        hashMap.put("signType", signType);

        log.info("niuniu:" + Util.sortKey(hashMap));
        if (!responseState.equals("1")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(mchId);
        searchPayInfo.getParams().put("payerName", "新牛牛支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        String signTemp = Util.sortKey(hashMap) + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, sign.toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(orderNo);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(amount)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "SUCCESS";
        } else {
            return "error";
        }
    }

    /**
     * 聚核支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("juhe")
    @ResponseBody
    public String updatJuHeOrder(String mch_id,String order_no,String out_trade_no,String pay_time,String timestamp,String total_fee,String sign) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
//        log.info("dashi:fxid="+fxid+"&fxddh="+fxddh+"&fxorder="+fxorder+"&fxdesc="+fxdesc+"&fxfee="+fxfee+"&fxattch="+fxattch+"&fxstatus="+fxstatus+"&fxtime="+fxtime+"&fxsign="+fxsign);
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(mch_id);
        searchPayInfo.getParams().put("payerName", "聚核支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }
        String signTemp = "mch_id="+mch_id+"&mch_secret="+payerInfos.get(0).getApiKey()+"&order_no="+order_no
                +"&out_trade_no="+out_trade_no+"&pay_time="+pay_time+"&timestamp="+timestamp+"&total_fee="+total_fee;
//        String signTemp = "fxstatus="+fxstatus+"&fxid="+fxid +"&fxddh="+fxddh+"&fxfee="+fxfee+"&"+ payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, sign.toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(out_trade_no);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(total_fee)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success".toUpperCase();
        } else {
            return "error";
        }
    }

    /**
     * 南北支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @GetMapping("nanbei")
    @ResponseBody
    public String updatNanBeiOrder(String mch_uid,String out_trade_no,String transaction_id,String total_fee,String real_fee,String pay_type,String status,String timestamp,String paytime,String sign) {
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(mch_uid);
        searchPayInfo.getParams().put("payerName", "南北支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }
        String signTemp="mch_uid="+mch_uid+"&out_trade_no="+out_trade_no+"&pay_type="+pay_type
                +"&paytime="+paytime+"&real_fee="+real_fee
                +"&status="+status+ "&timestamp="+timestamp+"&total_fee="+total_fee+"&transaction_id="+transaction_id;
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp+payerInfos.get(0).getApiKey(), sign.toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(out_trade_no);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(real_fee)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success".toUpperCase();
        } else {
            return "error";
        }
    }


    /**
     * 恭喜发财
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("GXFC")
    @ResponseBody
    public String updatGXFCOrder(@RequestBody Map<String, String> params) {
        // 第三方创建订单接口
        // 获取商户信息
        String reqJson = JSONObject.toJSONString(params);
        log.info("updatGXFCOrder: {}",reqJson);
        String code=params.get("code");
        String txcode=params.get("txCode");
        String txMsg=params.get("txMsg");
        String message=params.get("message");
        String sign=params.get("sign");
        params.remove("code");
        params.remove("txCode");
        params.remove("txMsg");
        params.remove("message");
        params.remove("sign");
        log.info("demoNotifyCallback code {},txcode {}, txMsg {}，message {}",code,txcode,txMsg,message);
        if(null !=txcode && !txcode.equals("orderRepairNotify") && !txcode.equals("orderNotify")){
            log.info("非补单或者订单回调");
            return "非补单或者订单回调";
//            if(txcode.equals("serverUrl")){//服务器地址
//
//            }else if(txcode.equals("withdraw")){//用户体现
//
//            }else if(txcode.equals("orderRepairNotify")){//订单补单回调
//                orderRepairNotify(params);
//            }else if(txcode.equals("orderNotify")){//订单回调
//                orderNotify(params);
//            }
        }

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(params.get("mch_secret"));
        searchPayInfo.getParams().put("payerName", "恭喜发财");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }
//        String signTemp="mch_uid="+mch_uid+"&out_trade_no="+out_trade_no+"&pay_type="+pay_type
//                +"&paytime="+paytime+"&real_fee="+real_fee
//                +"&status="+status+ "&timestamp="+timestamp+"&total_fee="+total_fee+"&transaction_id="+transaction_id;
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
//        boolean b = Md5Utils.vertifyAndroidMD5(signTemp+payerInfos.get(0).getApiKey(), sign.toLowerCase());

        SignUtil.getSign(params, payerInfos.get(0).getApiKey());
        if (params.get("sign").equals(sign) == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(params.get("out_trade_no"));
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(params.get("total_fee"))));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation("荷花支付中间页面")
    @GetMapping("hehuaView/{orderId}")
    public String hehuaView(@PathVariable("orderId") String orderId, ModelMap mmap) {

        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "荷花支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/hehua";
        String returnUrl = channelOrder.getReturnUrl();
        if (returnUrl == null || "".equals(returnUrl)) {
            returnUrl = payConfig.getPayCenterHost() + "/pay/orderSuccess/" + channelOrder.getOrderId();
        }
        try {
            HashMap<String,String> hashMap = new HashMap<>();
            hashMap.put("mch_id",businessRate.getPayerBusinessId());
            hashMap.put("mch_trade_no",channelOrder.getPtOrderno());
            hashMap.put("pay_type",businessRate.getPayerPayType());
            String amount = (channelOrder.getAmount().multiply(BigDecimal.valueOf(100L)) + "").replace(".00", "").replace(".0", "");
            hashMap.put("total_fee",amount);
            hashMap.put("notify_url",callbackUrl);
            hashMap.put("front_url",returnUrl);
            hashMap.put("nonce_str",System.currentTimeMillis()+"");
            hashMap.put("goods_name","test");
            hashMap.put("goods_desc","test");
            String sortParam = Util.sortKey(hashMap);
            String sign = Md5Utils.androidMD5(sortParam+"&key="+payerInfos.get(0).getApiKey());
            hashMap.put("sign",sign);
            //生成请求的链接地址
            mmap.put("payUri", payerInfo.getServiceUrl());
            mmap.addAllAttributes(hashMap);
        } catch (Exception e) {
        }
        return "HEHUA";
    }


    /**
     * 荷花支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("hehua")
    @ResponseBody
    public String updatNanBeiOrder(String mch_id,String mch_trade_no,String trade_no,String trade_state,String total_fee,String nonce_str,String sign) {
        HashMap<String,String> hashMap = new HashMap<>();
        hashMap.put("mch_id",mch_id);
        hashMap.put("mch_trade_no",mch_trade_no);
        hashMap.put("trade_no",trade_no);
        hashMap.put("trade_state",trade_state);
        hashMap.put("total_fee",total_fee);
        hashMap.put("nonce_str",nonce_str);
        log.info("荷花回调："+hashMap.toString()+";sign:"+sign);
        if(!trade_state.equals("SUCCESS")){
            return "UNSUCCESS";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(mch_id);
        searchPayInfo.getParams().put("payerName", "荷花支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        String sortParam = Util.sortKey(hashMap);
        boolean b = Md5Utils.vertifyAndroidMD5(sortParam+"&key="+payerInfos.get(0).getApiKey(), sign.toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(mch_trade_no);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(total_fee)/100)); // 取回来的是分 要除以100
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success".toUpperCase();
        } else {
            return "error";
        }
    }

    /**
     * 国际支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("guoji")
    @ResponseBody
    public String updatGuojiOrder(@RequestBody GuoJiCallMsg callMsg) {
        log.info("国际支付："+callMsg.toString());
        String _context = new String(Base64.getDecoder().decode(callMsg.getContext())) ;
        JSONObject jsonObject = JSONObject.parseObject(_context);
        if(!jsonObject.getString("orderState").equals("1")){
            log.info("updatGuojiOrder订单失败");
            return "订单失败";
        }

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(jsonObject.getString("attach"));
        searchPayInfo.getParams().put("payerName", "国际支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        boolean b = Md5Utils.vertifyAndroidMD5(_context +payerInfos.get(0).getApiKey(), callMsg.getSign().toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(jsonObject.getString("orderNo"));
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(jsonObject.getString("realAmount")))); // 取回来的是分 要除以100
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "ok";
        } else {
            return "error";
        }
    }

    /**
     * 泡泡支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("paopao/{id}")
    @ResponseBody
    public String updatPaoPaoOrder(@PathVariable("id") String id,String orderNo,String tradeNo,String amount,String tradeTime,String status,String sign) {
        log.info("泡泡支付："+orderNo+";"+ tradeNo +";"+  amount +";"+  tradeTime +";"+   status +";"+  sign);
        if(!status.equals("1")){
            log.info("updatPaoPaoOrder订单失败");
            return "订单失败";
        }

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(id);
        searchPayInfo.getParams().put("payerName", "泡泡支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        String signTemp="amount="+amount+"&orderNo="+orderNo+"&status="+status+"&tradeNo="+tradeNo
                +"&tradeTime="+tradeTime;

        boolean b = Md5Utils.vertifyAndroidMD5(signTemp +"key="+payerInfos.get(0).getApiKey(), sign);
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(orderNo);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(amount))); // 取回来的是分 要除以100
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "0000";
        } else {
            return "error";
        }
    }

    /**
     * 鑫和支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("shenqi")
    @ResponseBody
    public String updatShenqiOrder(@RequestBody PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info("updatShenqiOrder:"+pddCallMsg.toString());
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("memberid", pddCallMsg.getMemberid());
        hashMap.put("orderid", pddCallMsg.getOrderid());
        hashMap.put("amount", pddCallMsg.getAmount()+"");
        hashMap.put("transaction_id", pddCallMsg.getTransaction_id());
        hashMap.put("datetime", pddCallMsg.getDatetime());
        hashMap.put("returncode", pddCallMsg.getReturncode());
        hashMap.put("returnmsg", pddCallMsg.getReturnmsg());
//        hashMap.put("failMsg", pddCallMsg.getFailMsg());
//        hashMap.put("attach", pddCallMsg.getAttach());
        log.info("xinhe:" + Util.sortKey(hashMap));
        if (!pddCallMsg.getReturncode().equals("00")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(pddCallMsg.getMemberid());
        searchPayInfo.getParams().put("payerName", "神奇支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }
        String signTemp = Util.sortKey(hashMap) + "&key=" + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, pddCallMsg.getSign().toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(pddCallMsg.getOrderid());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(channelOrders.get(0).getAmount());
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "0000";
        } else {
            return "error";
        }
    }

    /**
     * 下游支付商调用的接口,告诉支付中心 订单已经完成了
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("xiyou")
    @ResponseBody
    public String updateXiyouOrder(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        return updateZYOrder(pddCallMsg, "西游支付");
    }


    /**
     * 浩然支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @GetMapping("haoran")
    @ResponseBody
    public String updatHaoRanOrder(String mch_uid,String out_trade_no,String transaction_id,String total_fee,String real_fee,String pay_type,String status,String timestamp,String paytime,String sign) {
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(mch_uid);
        searchPayInfo.getParams().put("payerName", "浩然支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }
        String signTemp="mch_uid="+mch_uid+"&out_trade_no="+out_trade_no+"&pay_type="+pay_type
                +"&paytime="+paytime+"&real_fee="+real_fee
                +"&status="+status+ "&timestamp="+timestamp+"&total_fee="+total_fee+"&transaction_id="+transaction_id;
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp+payerInfos.get(0).getApiKey(), sign.toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(out_trade_no);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(real_fee)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success".toUpperCase();
        } else {
            return "error";
        }
    }

    @ApiOperation("首创支付中间页面")
    @GetMapping("shouchuangView/{orderId}")
    public String shouchuangView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/shouchuang";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "首创支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }
        String returnUrl = channelOrder.getReturnUrl();
        if (returnUrl == null || "".equals(returnUrl)) {
            returnUrl = payConfig.getPayCenterHost() + "/pay/orderSuccess/" + channelOrder.getOrderId();
        }
        long sendTime = System.currentTimeMillis() / 1000;
        String stringSignTemp = "merchant=" + businessRate.getPayerBusinessId() + "&qrtype=" + businessRate.getPayerPayType() + "&customno=" + channelOrder.getPtOrderno() + "&money=" + channelOrder.getAmount()
                + "&sendtime=" + sendTime
                + "&notifyurl=" + callbackUrl + "&backurl=" + returnUrl + "&risklevel=";
//        String stringSignTemp = "pay_amount=" + channelOrder.getAmount() + "&pay_applydate=" + time + "&pay_bankcode=" + businessRate.getPayerPayType() + "&pay_callbackurl=" + callbackUrl + "&pay_memberid=" + businessRate.getPayerBusinessId() + "&pay_notifyurl=" + callbackUrl + "&pay_orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            sign = Md5Utils.androidMD5(stringSignTemp + payerInfos.get(0).getApiKey());
        } catch (Exception e) {
        }
        RYCallMsg yhbCallMsg = new RYCallMsg();
        yhbCallMsg.setMerchant(businessRate.getPayerBusinessId());
        yhbCallMsg.setQrtype(businessRate.getPayerPayType());
        yhbCallMsg.setCustomno(channelOrder.getPtOrderno());
        yhbCallMsg.setMoney(channelOrder.getAmount() + "");
        yhbCallMsg.setSendtime(sendTime + "");
        yhbCallMsg.setNotifyurl(callbackUrl);
        yhbCallMsg.setBackurl(returnUrl);
        yhbCallMsg.setSign(sign);
//        stringBuilder.append("&pay_productnum=");
//        stringBuilder.append("&pay_productdesc=");
//        stringBuilder.append("&pay_producturl=");
        mmap.put("yhbCallMsg", yhbCallMsg);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "QUANRONG";
    }

    /**
     * 全荣支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("shouchuang")
    @ResponseBody
    public String updatShouChuangOrder(RYCallMsg ryCallMsg) {

        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info("shouchuang:" + ryCallMsg.toString());
        if (!ryCallMsg.getState().equals("1")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(ryCallMsg.getMerchant());
        searchPayInfo.getParams().put("payerName", "首创支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        String signTemp = "merchant=" + ryCallMsg.getMerchant() + "&merchant_money=" + ryCallMsg.getMerchant_money() + "&qrtype=" + ryCallMsg.getQrtype() + "&customno=" + ryCallMsg.getCustomno()
                + "&sendtime=" + ryCallMsg.getSendtime() + "&orderno=" + ryCallMsg.getOrderno()
                + "&money=" + ryCallMsg.getMoney() + "&paytime=" + ryCallMsg.getPaytime()
                + "&state=" + ryCallMsg.getState() + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, ryCallMsg.getSign());
        if (b == false) {
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(ryCallMsg.getCustomno());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(ryCallMsg.getMoney())));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation("顺恒网关支付中间页面")
    @GetMapping("shunhewgView/{orderId}")
    public String shunhewgView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/shunhewg";
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "顺恒网关");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }

        String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String amount = (channelOrder.getAmount().multiply(BigDecimal.valueOf(100L)) + "").replace(".00", "").replace(".0", "");
        String str = "currencyCode=156&merNo="+businessRate.getPayerBusinessId()+"&merOrderId="+channelOrder.getOrderId()+"&orderDesc=test&txnAmt="+amount+"&txnTime="+time;
        String sign = Md5Utils.getSHA256(str+"&"+payerInfos.get(0).getApiKey());
        String result = HttpUtils.sendPost2(payerInfo.getServiceUrl(),str+"&signature="+sign);
        System.out.println("setToPDDNextOrder:" + result);
        mmap.put("url", result.replace("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/></head><body>", "").replace("</body>", "").replace("</html>", ""));
        return "WEIFU";
    }

    /**
     * 全荣支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("顺恒网关更新订单")
    @PostMapping("shunhewg")
    @ResponseBody
    public String updatShenhengOrder(String merNo,String merOrderId,String queryId,String resultCode,String resultMsg,String respCode,String respMsg,String txnTime,String txnAmt,String settleCurrencyCode,String settleAmt,String settleDate,String traceNo,String signature) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info("updatShenhengOrder:merNo:" + merNo +";merOrderId:"+ merOrderId+";queryId"+ queryId+";resultCode:"+resultCode+";resultCode:"+resultMsg+";respCode:"+respCode+";respMsg:"+respMsg+";txnTime:"+txnTime+";txnAmt:"+txnAmt+";settleCurrencyCode:"+settleCurrencyCode+";settleAmt:"+settleAmt+";settleDate:"+settleDate+";traceNo:"+traceNo+";signature:"+signature);
        if (!resultCode.equals("0000")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(merNo);
        searchPayInfo.getParams().put("payerName", "顺恒网关");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        HashMap<String,String> hashMap = new HashMap<>();
        hashMap.put("merNo",merNo);
        hashMap.put("merOrderId",merOrderId);
        hashMap.put("queryId",queryId);
//        channelOrders.get(0).setPayAmount(vnetCallMsg.getAmount().divide(BigDecimal.valueOf(100L))); // 取回来的是分 要除以100
        hashMap.put("resultCode",resultCode);
        hashMap.put("resultMsg",resultMsg);
        hashMap.put("respCode",respCode);
        hashMap.put("respMsg",respMsg);
        hashMap.put("txnTime",txnTime);
        hashMap.put("txnAmt",txnAmt);
        hashMap.put("settleCurrencyCode",settleCurrencyCode);
        hashMap.put("settleAmt",settleAmt);
        hashMap.put("settleDate",settleDate);
        hashMap.put("traceNo",traceNo);
        String sortParam = Util.sortKey(hashMap);
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(sortParam+"&"+payerInfos.get(0).getApiKey(), signature);
        if (b == false) {
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(merOrderId);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }
//        channelOrders.get(0).setPayAmount(vnetCallMsg.getAmount().divide(BigDecimal.valueOf(100L))); // 取回来的是分 要除以100
        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(txnAmt)));
        channelOrders.get(0).setPayAmount(channelOrders.get(0).getAmount().divide(BigDecimal.valueOf(100L)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 自由支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @GetMapping("ziyou")
    @ResponseBody
    public String updateZiYouOrder(String mch_uid,String out_trade_no,String transaction_id,String total_fee,String real_fee,String pay_type,String status,String timestamp,String paytime,String sign) {
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(mch_uid);
        searchPayInfo.getParams().put("payerName", "自由支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("找到多个商户");
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }
        String signTemp="mch_uid="+mch_uid+"&out_trade_no="+out_trade_no+"&pay_type="+pay_type
                +"&paytime="+paytime+"&real_fee="+real_fee
                +"&status="+status+ "&timestamp="+timestamp+"&total_fee="+total_fee+"&transaction_id="+transaction_id;
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp+payerInfos.get(0).getApiKey(), sign.toLowerCase());
        if (b == false) {
            log.info("验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(out_trade_no);
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(real_fee)));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success".toUpperCase();
        } else {
            return "error";
        }
    }

    @ApiOperation("梦支付中间页面")
    @GetMapping("yhbView/{orderId}")
    public String yhbView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/yhb";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "亿汇宝");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }

        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        String stringSignTemp = "pay_amount=" + channelOrder.getAmount() + "&pay_applydate=" + time + "&pay_bankcode=" + businessRate.getPayerPayType() + "&pay_callbackurl=" + callbackUrl + "&pay_memberid=" + businessRate.getPayerBusinessId() + "&pay_notifyurl=" + callbackUrl + "&pay_orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            sign = Md5Utils.androidMD5(stringSignTemp).toUpperCase();
        } catch (Exception e) {
        }
        YhbCallMsg yhbCallMsg = new YhbCallMsg();
        yhbCallMsg.setPay_memberid(businessRate.getPayerBusinessId());
        yhbCallMsg.setPay_orderid(channelOrder.getPtOrderno());
        yhbCallMsg.setPay_applydate(time);
        yhbCallMsg.setPay_bankcode(businessRate.getPayerPayType());
        yhbCallMsg.setPay_notifyurl(callbackUrl);
        yhbCallMsg.setPay_callbackurl(callbackUrl);
        yhbCallMsg.setPay_amount(channelOrder.getAmount());
        yhbCallMsg.setPay_md5sign(sign);
        yhbCallMsg.setPay_productname("收款");
//        stringBuilder.append("&pay_productnum=");
//        stringBuilder.append("&pay_productdesc=");
//        stringBuilder.append("&pay_producturl=");
        mmap.put("yhbCallMsg", yhbCallMsg);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "MZF";
    }

    /**
     * 下游支付商调用的接口,告诉支付中心 订单已经完成了
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("yhb")
    @ResponseBody
    public String updatYhbOrder(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(pddCallMsg.toString());
        if (!pddCallMsg.getReturncode().equals("00")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(pddCallMsg.getMemberid());
        searchPayInfo.getParams().put("payerName", "亿汇宝");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }

        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }
        // 开始签名
        String signTemp = "amount=" + pddCallMsg.getAmount() + "&datetime=" + pddCallMsg.getDatetime() + "&memberid="
                + pddCallMsg.getMemberid() + "&orderid=" + pddCallMsg.getOrderid() + "&request_amount=" + pddCallMsg.getRequest_amount() +
                "&returncode=" + pddCallMsg.getReturncode() + "&transaction_id=" +
                pddCallMsg.getTransaction_id() + "&key=" + payerInfos.get(0).getApiKey() + "";
        log.info(signTemp);
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, pddCallMsg.getSign());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatePddOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(pddCallMsg.getOrderid());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到两条相同的数据";
        }
        channelOrders.get(0).setPayAmount(pddCallMsg.getAmount());
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "OK";
        } else {
            return "ERROR";
        }
    }

    @ApiOperation("三金支付中间页面")
    @GetMapping("sanjinView/{orderId}")
    public String sanjinView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/sanjin";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "三金支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }

        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        String stringSignTemp = "amount=" + channelOrder.getAmount() + "&applydate=" + time + "&bankcode=" + businessRate.getPayerPayType() + "&callbackurl=" + callbackUrl + "&memberid=" + businessRate.getPayerBusinessId() + "&notifyurl=" + callbackUrl + "&orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            sign = Md5Utils.androidMD5(stringSignTemp).toUpperCase();
        } catch (Exception e) {
        }
        SanJinCallMsg yhbCallMsg = new SanJinCallMsg();
        yhbCallMsg.setMemberid(businessRate.getPayerBusinessId());
        yhbCallMsg.setOrderid(channelOrder.getPtOrderno());
        yhbCallMsg.setApplydate(time);
        yhbCallMsg.setBankcode(businessRate.getPayerPayType());
        yhbCallMsg.setNotifyurl(callbackUrl);
        yhbCallMsg.setCallbackurl(callbackUrl);
        yhbCallMsg.setAmount(channelOrder.getAmount());
        yhbCallMsg.setMd5sign(sign);
        yhbCallMsg.setProductname("收款");
//        stringBuilder.append("&pay_productnum=");
//        stringBuilder.append("&pay_productdesc=");
//        stringBuilder.append("&pay_producturl=");
        mmap.put("yhbCallMsg", yhbCallMsg);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "SANJIN";
    }

    /**
     * 下游支付商调用的接口,告诉支付中心 订单已经完成了
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("sanjin")
    @ResponseBody
    public String updateSanJinOrder(PddCallMsg pddCallMsg) {
        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info(pddCallMsg.toString());
        if (!pddCallMsg.getReturncode().equals("00")) {
            log.info("updateZYOrder 00 失败");
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(pddCallMsg.getMemberid());
        searchPayInfo.getParams().put("payerName", "三金支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            log.info("updateZYOrder 找不到商户");
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            log.info("updateZYOrder 找到多个商户");
            return "找到多个商户";
        }

        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        // 开始签名
        String signTemp = "amount=" + pddCallMsg.getAmount() + "&datetime=" + pddCallMsg.getDatetime() + "&memberid=" + pddCallMsg.getMemberid()
                + "&orderid=" + pddCallMsg.getOrderid() + "&returncode=" +
                pddCallMsg.getReturncode() + "&transaction_id=" + pddCallMsg.getTransaction_id() + "&key=" + payerInfos.get(0).getApiKey() + "";
        log.info(signTemp);
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, pddCallMsg.getSign());
        if (b == false) {
            // 如果校验失败要告警 TODO:
            log.error("updatePddOrder验签失败");
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(pddCallMsg.getOrderid());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            log.info("updateZYOrder 找到多个商户");
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            log.info("updateZYOrder 找到两条相同的数据");
            return "找到两条相同的数据";
        }
        channelOrders.get(0).setPayAmount(pddCallMsg.getAmount());
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "OK";
        } else {
            return "ERROR";
        }
    }

    @ApiOperation("阳光支付中间页面")
    @GetMapping("yangguangView/{orderId}")
    public String yangguangView(@PathVariable("orderId") String orderId, ModelMap mmap) {
        String callbackUrl = payConfig.getPayCenterHost() + "/callback/yangguang";
        ChannelOrder channelOrder = channelOrderService.selectChannelOrderById(orderId);
        BusinessRate businessRate = businessRateService.selectBusinessRateById(channelOrder.getBusinessRateId());
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(channelOrder.getPayerUserId());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(businessRate.getPayerBusinessId());
        searchPayInfo.getParams().put("payerName", "代理中心");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            mmap.put("msg", "找不到商户");
            return "openError";
        }
        if (payerInfos.size() > 1) {
            mmap.put("msg", "找到多个商户");
            return "openError";
        }
        String returnUrl = channelOrder.getReturnUrl();
        if (returnUrl == null || "".equals(returnUrl)) {
            returnUrl = payConfig.getPayCenterHost() + "/pay/orderSuccess/" + channelOrder.getOrderId();
        }
        long sendTime = System.currentTimeMillis();
        String stringSignTemp = "businessId=" + payerInfos.get(0).getBusinessNo() + "&payType=" + businessRate.getPayerPayType()
                + "&childOrderno=" + channelOrder.getPtOrderno() + "&amount=" + channelOrder.getAmount() + "&time=" + sendTime;
//        String stringSignTemp = "pay_amount=" + channelOrder.getAmount() + "&pay_applydate=" + time + "&pay_bankcode=" + businessRate.getPayerPayType() + "&pay_callbackurl=" + callbackUrl + "&pay_memberid=" + businessRate.getPayerBusinessId() + "&pay_notifyurl=" + callbackUrl + "&pay_orderid=" + channelOrder.getPtOrderno() + "&key=" + payerInfos.get(0).getApiKey();
        String sign = "";
        try {
            log.info("笨鸟加密字符串：" + stringSignTemp);
            sign = Md5Utils.androidMD5(stringSignTemp + "&" + payerInfos.get(0).getApiKey());
        } catch (Exception e) {
        }
        channelOrder.setServerUrl(callbackUrl);
        channelOrder.setBusinessId(Long.valueOf(payerInfos.get(0).getBusinessNo()));
        channelOrder.setReturnUrl(returnUrl);
        channelOrder.setChildOrderno(channelOrder.getPtOrderno());
        mmap.put("sign", sign);
        mmap.put("time", sendTime);
        mmap.put("channelOrder", channelOrder);
        mmap.put("payUri", payerInfo.getServiceUrl());
        return "BENNIAO";
    }

    /**
     * 阳光支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("yangguang")
    @ResponseBody
    public String updatYangGuangOrder(ChannelOrder callOrder, String time, String sign) {

        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info("benniao:" + callOrder.toString());
        if (!callOrder.getOrderStatus().equals("1") && !callOrder.getOrderStatus().equals("2") && !callOrder.getOrderStatus().equals("3")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(callOrder.getBusinessId() + "");
        searchPayInfo.getParams().put("payerName", "代理中心");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP"+host);
            return "非法IP";
        }



        String signTemp = "childOrderno=" + callOrder.getChildOrderno() + "&payAmount=" + callOrder.getPayAmount() + "&orderStatus=" + callOrder.getOrderStatus() + "&time=" + time + "&" + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, sign);
        if (b == false) {
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(callOrder.getChildOrderno());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(callOrder.getPayAmount());
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 代付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("withdraw")
    @ResponseBody
    public String updatWithdraw(ChannelOrder callOrder, String time, String sign) {

        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info("updatWithdraw:" + callOrder.toString());

        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(callOrder.getBusinessId() + "");
        searchPayInfo.getParams().put("payerName", "代理中心");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP"+host);
            return "非法IP";
        }

        String signTemp = "childOrderno=" + callOrder.getChildOrderno() + "&payAmount=" + callOrder.getPayAmount() + "&orderStatus=" + callOrder.getOrderStatus() + "&time=" + time + "&" + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, sign);
        if (b == false) {
            return "验签失败";
        }
        BusinessCapital businessCapital = businessCapitalService.selectBusinessCapitalById(callOrder.getChildOrderno());
        if (businessCapital == null) {
            return "找不到订单号";
        }
        if (businessCapital.getRealAmount().compareTo(callOrder.getPayAmount()) != 0) {
            return "下发金额和下单金额不一致";
        }
        AjaxResult ajaxResult = businessCapitalService.changeStatus("3", callOrder.getChildOrderno());
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 全荣支付回调接口
     *
     * @param
     * @return
     */
    @ApiOperation("更新订单")
    @PostMapping("maya")
    @ResponseBody
    public String updatMayaOrder(RYCallMsg ryCallMsg) {

        // 第三方创建订单接口
        // 获取商户信息
        // md5秘钥校验
        log.info("quanrong:" + ryCallMsg.toString());
        if (!ryCallMsg.getState().equals("1")) {
            return "error";
        }
        PayerBusinessInfo searchPayInfo = new PayerBusinessInfo();
        searchPayInfo.setBusinessNo(ryCallMsg.getMerchant());
        searchPayInfo.getParams().put("payerName", "玛雅支付");
        List<PayerBusinessInfo> payerInfos = payerBusinessInfoService.selectPayerBusinessInfoList(searchPayInfo);
        if (payerInfos.size() == 0) {
            return "找不到商户";
        }
        if (payerInfos.size() > 1) {
            return "找到多个商户";
        }
        PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerInfos.get(0).getPayerId());
        String host = ServletUtils.getRequest().getRemoteHost();
        String[] ips = payerInfo.getServiceIp().split(",");
        boolean flag = false;
        for (int i = 0; i < ips.length; i++) {
            if (ips[i].equals(host)) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            log.info("非法IP");
            return "非法IP";
        }

        String signTemp = "merchant=" + ryCallMsg.getMerchant() + "&merchant_money=" + ryCallMsg.getMerchant_money() + "&qrtype=" + ryCallMsg.getQrtype() + "&customno=" + ryCallMsg.getCustomno()
                + "&sendtime=" + ryCallMsg.getSendtime() + "&orderno=" + ryCallMsg.getOrderno()
                + "&money=" + ryCallMsg.getMoney() + "&paytime=" + ryCallMsg.getPaytime()
                + "&state=" + ryCallMsg.getState() + payerInfos.get(0).getApiKey();
        // 开始签名
        // String signTemp =  ddCallMsg.getAmount()+ddCallMsg.getMerchantNo()+ddCallMsg.getMerchantOrderNo()+ddCallMsg.getReal()+ddCallMsg.getStatus() +ddCallMsg.getTransNo()+payerInfos.get(0).getApiKey();
        boolean b = Md5Utils.vertifyAndroidMD5(signTemp, ryCallMsg.getSign());
        if (b == false) {
            return "验签失败";
        }
        ChannelOrder searchOrder = new ChannelOrder();
        searchOrder.setPayerUserId(payerInfos.get(0).getPayerId());
        searchOrder.setPtOrderno(ryCallMsg.getCustomno());
        List<ChannelOrder> channelOrders = channelOrderService.selectChannelOrderList(searchOrder);
        if (channelOrders.size() == 0) {
            return "找不到订单号";
        }
        if (channelOrders.size() > 1) {
            return "找到多条相同的数据";
        }
        if (!channelOrders.get(0).getOrderStatus().equals("0")) {
            return "单子已经过期或者已经成功,请勿重复更新";
        }

        channelOrders.get(0).setPayAmount(BigDecimal.valueOf(Double.valueOf(ryCallMsg.getMoney())));
        channelOrders.get(0).setOrderId(channelOrders.get(0).getPtOrderno());
        AjaxResult ajaxResult = payService.updateOrder(channelOrders.get(0));
        log.info(ajaxResult.get("code") + ";" + ajaxResult.get("msg"));
        if (0 == (int) ajaxResult.get("code")) {
            return "success";
        } else {
            return "error";
        }
    }
}


